#include "Setting.h"
#include "Fighting.h"
using namespace cocos2d;
enum {
	kTagSprite2,
};
CCScene* Setting::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::node();
        CC_BREAK_IF(! scene);

        // 'layer' is an autorelease object
        Setting *layer = Setting::node();
        CC_BREAK_IF(! layer);
		
        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool Setting::init()
{
	
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());
		//set the background
		CCSize size = CCDirector::sharedDirector()->getWinSize();
        CCSprite* pSprite = CCSprite::spriteWithFile("res/setting.png");
        CC_BREAK_IF(! pSprite);
        pSprite->setPosition(ccp(size.width/2, size.height/2));
        this->addChild(pSprite, 0);
		//build menu background
		CCSprite* pSetting_bg = CCSprite::spriteWithFile("res/setting_bg.png");
        CC_BREAK_IF(! pSetting_bg);
        pSetting_bg->setPosition(ccp(size.width/4, size.height/2));
        this->addChild(pSetting_bg, 0);
		//weapon
        CCMenuItemImage *pWeaponOneItem = CCMenuItemImage::itemFromNormalImage(
            "res/weapon.png",
            "res/weapon.png",
            this,
            menu_selector(Setting::menuWeaponOneCallback));
        CC_BREAK_IF(! pWeaponOneItem);
		pWeaponOneItem->setPosition(ccp(size.width/8,size.height/2));
		//
		CCMenuItemImage *pWeaponTwoItem = CCMenuItemImage::itemFromNormalImage(
            "res/weapon.png",
            "res/weapon.png",
            this,
            menu_selector(Setting::menuWeaponTwoCallback));
        CC_BREAK_IF(! pWeaponTwoItem);
		pWeaponTwoItem->setPosition(ccp(size.width/8,size.height/8*3));
		//
		CCMenuItemImage *pWeaponThreeItem = CCMenuItemImage::itemFromNormalImage(
            "res/weapon.png",
            "res/weapon.png",
            this,
            menu_selector(Setting::menuWeaponThreeCallback));
        CC_BREAK_IF(! pWeaponThreeItem);
		pWeaponThreeItem->setPosition(ccp(size.width/8,size.height/4));
		//
		CCMenu* pMenu = CCMenu::menuWithItems(pWeaponOneItem, NULL);
		pMenu->addChild(pWeaponTwoItem,0);
		pMenu->addChild(pWeaponThreeItem,0);

        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);
        pSetting_bg->addChild(pMenu, 1);
		//count
		CCLabelAtlas* label2 = CCLabelAtlas::labelWithString("110", "res/fonts/tuffy_bold_italic-charmap.png", 48, 64, ' ');
	    addChild(label2, 0,kTagSprite2);
		label2->setPosition( ccp(size.width/4,size.height/2) );
	    label2->setColor( ccRED );
        bRet = true;
    } while (0);

    return bRet;
}
void Setting::menuWeaponOneCallback(CCObject* pSender)
{
    // "close" menu item clicked
	CCLabelAtlas* pLabel=(CCLabelAtlas*)getChildByTag(kTagSprite2);
	pLabel->setString("selected one weapon");
}
void Setting::menuWeaponTwoCallback(CCObject* pSender)
{
    // "close" menu item clicked
    CCDirector::sharedDirector()->replaceScene(CCTransitionZoomFlipY::transitionWithDuration(1.0,Fighting::scene(), kOrientationDownOver));
}
void Setting::menuWeaponThreeCallback(CCObject* pSender)
{
    // "close" menu item clicked
    CCDirector::sharedDirector()->end();
}